package com.tanhua.admin.controller;

import com.tanhua.admin.service.ManageService;
import com.tanhua.model.db.UserInfo;
import com.tanhua.model.vo.PageResult;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/manage")
public class ManageController {  //分页查询用户列表
    @Autowired
    private ManageService manageService;
    @GetMapping("/users")
    public ResponseEntity users(@RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer pageSize
                                ){
     PageResult pageResult = manageService.findByPage(page,pageSize);
     return ResponseEntity.ok(pageResult);
    }
   //查询用户基本信息
   @GetMapping("/users/{userId}")
    public ResponseEntity user(@PathVariable("userId") Long userId){
        //info表的id就是用户的id
       UserInfo info = manageService.findById(userId);
        return ResponseEntity.ok(info);
   }
   //查询用户发布的视频列表
    @GetMapping("/videos")
    public ResponseEntity videos(@RequestParam(defaultValue = "1") Integer page,
                                 @RequestParam(defaultValue = "10") Integer pageSize,
                                 Long uid){
     PageResult vo = manageService.findVideosById(page,pageSize,uid);
     return ResponseEntity.ok(vo);
    }
    //查询用户动态列表  ,,对应动态审核和个人动态信息接口，可能不传用户id或
    @GetMapping("/messages")
    public ResponseEntity messages(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer pageSize,
                                   Long uid,
                                   String state){
         //页面传入的state参数有问题,传空(审核)时是单引号
        Integer status = null;
        if (!StringUtils.isEmpty(state)&&!"''".equals(state)){
           status = Integer.valueOf(state);
        }
        PageResult pageResult = manageService.findMovement(status,page,pageSize,uid);
        return ResponseEntity.ok(pageResult);
    }
}
